<?php
/*
* File function.minhournotation.php for project Rijlesplanner.nl
* Created on 24 feb 2009 by Niek
*/

/**
* Displays the error messages it is given in a uniform manner
* @tutorial http://www.smarty.net/manual/en/plugins.functions.php
* @param int $minuten The minuten passed to this function from the Smarty template
*/
function smarty_function_minhournotation($params, &$smarty) {
	$minuten = (int)$params['minuten'];
	$res = minToHourMinNotation($minuten);
	return $res;
}

/**
* Translate pure minutes into hour minutes notation (example 370 min -> 6 uur 10 min)
* Taken from shared/DationUtils
*/
function minToHourMinNotation($minutes) {
	if ($minutes == 0) {
		return '0 min';
	}

	if ($minutes < 0) {
		$negatief = true;
		$minutes = abs($minutes);
	} else {
		$negatief = false;
	}

	$hour = (int)floor($minutes/60);
	$min = (int)$minutes % 60;
	if ($hour == 0) {
		$hour = "";
	} else {
		$hour = $hour . ' uur';
	}
	if ($min == 0) {
		$min = "";
	} else {
		$min = $min . ' min';
	}

	$res = ($negatief) ? '-' : '';
	$res .= $hour . " " . $min;
	return trim($res);
}
?>
